package com.javaee.wordtree.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.javaee.wordtree.entity.StoryTemplate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import java.util.List;

@Mapper
public interface StoryTemplateMapper extends BaseMapper<StoryTemplate> {
    
    @Select("SELECT * FROM story_templates WHERE JSON_CONTAINS(word_list, JSON_QUOTE(#{word})) LIMIT 1")
    StoryTemplate findByWordList(@Param("word") String word);
    
    @Select("SELECT * FROM story_templates WHERE difficulty_level = #{level} ORDER BY created_at DESC")
    List<StoryTemplate> findByDifficultyLevel(@Param("level") String level);
    
    @Select("SELECT * FROM story_templates ORDER BY created_at DESC LIMIT #{limit}")
    List<StoryTemplate> findLatestTemplates(@Param("limit") int limit);
}